package app.web.cartoon.report.year.tab;

import java.io.IOException;

import app.excel.cartoon.year.ExcelCartoonYear;
import app.web.cartoon.report.year.tool.CartoonFansReport;
import cn.lily.com.configure.util.ESBSetting;
import cn.lily.com.exception.YaconException;
import cn.lily.com.file.FilePath;
import cn.lily.com.file.zip.ZipFileUtil;
import cn.lily.com.lang.BusinessDate;
import cn.lily.web.page.BusinessPage;
import cn.lily.web.widget.sql.TSqlGrid;
import cn.lily.web.widget.standard.TButton;
import cn.lily.web.widget.standard.TButtonPilot;
/**
 * 番数统计信息
 * @author JiaJ
 *
 */
public class FansReport extends BusinessPage {

	@Override
	public void page_onLoad() throws YaconException {
		
		 TSqlGrid fansGrid = sqlGrid("fansGrid");
		 fansGrid.setDictTable("LEO_CAN_REPORT_FANS");
		 String sqlString = " select CAN_FANS,CAN_YEAR,CAN_MONTH,CAN_DETAIL_NUM,to_char(CAN_REP_DATE,'yyyy-mm-dd hh24:mi:ss') CAN_REP_DATE,CAN_REP_OPER "
		 				  + " from ${schema}.LEO_CAN_REPORT_FANS "
		 				  + " order by CAN_FANS DESC ";
		 fansGrid.setCommSqlStr(sqlString);
		 fansGrid.setEdit(true);

		 fansGrid.createFieldTitle("CAN_FANS");
		 fansGrid.createFieldTitle("CAN_YEAR");
		 fansGrid.createFieldTitle("CAN_MONTH");
		 fansGrid.createFieldTitle("CAN_DETAIL_NUM");
		 fansGrid.createFieldTitle("CAN_REP_DATE").setFieldVisible(false);
		 fansGrid.createFieldTitle("CAN_REP_OPER").setFieldVisible(false);
		 
		 TButtonPilot fansGridPilot = ButtonPilot("wordGridPilot");
		 fansGridPilot.setPilotIco("/widget/buttonPilot.gif");
		 fansGridPilot.setPilotText("动漫番数统计");

		 TButton fansReport = new TButton("fansGridBtn");
		 fansReport.setIcoPath("glyphicon glyphicon-th-large");
		 fansReport.setLabel("番数统计");
		 fansReport.setViewClick("fansGridBtn_onclick");
		 fansGridPilot.addButtons(fansReport);
		 
		 TButton dataYearExport = new TButton("dataYearExportBtn");
		 dataYearExport.setIcoPath("glyphicon glyphicon-download-alt");
		 dataYearExport.setLabel("年份导出");
		 dataYearExport.setViewClick("dataYearExportBtn_onclick");	
		 fansGridPilot.addButtons(dataYearExport);

		 fansGrid.setButtonPilot(fansGridPilot);
		 
		 fansGrid.setTopButtonType("all");
		 
		 getPage().addElement(fansGrid);
		
	}
	
	public void refresh(){
		 TSqlGrid fansGrid = sqlGrid("fansGrid");
		 String sqlString = " select CAN_FANS,CAN_YEAR,CAN_MONTH,CAN_DETAIL_NUM,to_char(CAN_REP_DATE,'yyyy-mm-dd hh24:mi:ss') CAN_REP_DATE,CAN_REP_OPER "
		 				  + " from ${schema}.LEO_CAN_REPORT_FANS "
		 				  + " order by CAN_FANS DESC ";
		 fansGrid.setCommSqlStr(sqlString);
		 this.setSelfMessage(fansGrid.getDataElement());
	}
	
	public void fansReport(){
		
		try {
			
			CartoonFansReport fansReport = new CartoonFansReport();
			fansReport.inst();
			
		} catch (Exception e) {
			e.printStackTrace();
			this.setSelfMessage("动漫番数统计失败！");
		}
		
		this.setSuccess("动漫番数统计成功！");
	}
	
	public void yearExport(){
		
		String filePath = "/file/cartoon/year/动漫年份整理【"+BusinessDate.getdayNumber()+"】.xlsx";
		
		String absolutePath = FilePath.getWebRootPath(filePath);
		
		ExcelCartoonYear excelYear = new ExcelCartoonYear();
		
		excelYear.setFilePath(absolutePath);
		
		excelYear.export();
		
		excelYear.free();
		
		try {
			ZipFileUtil.zipSingleFile(absolutePath, absolutePath+".zip");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		this.setSelfMessage("/"+ESBSetting.getString("appCode")+filePath+".zip");
		
	}

}
